﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace BZZ.Model
{
	/// <summary>
	/// 汽车维修信息实体类：carMaintainInfo 。
	/// </summary>
	[Serializable]
	public class carMaintainInfo
	{
        iData.DataAcess worker = new iData.DataAcess();
        public carMaintainInfo(int id=0)
		{
            if (id > 0) GetModel(id);
        }

        #region 公共方法

        #region 查询操作 
        /// <summary>
        /// 获取当前页的datatable
        /// </summary>
        /// <param name="dicCondition">条件词典</param>
        /// <returns></returns>
        public DataSet GetDataset(Dictionary<string, string> dicCondition)
        {
            string fields = "";
            var sb = new StringBuilder(512);
            sb.Append(" 1=1");
            var paraList = new List<SqlParameter>();

            ///查询条件
            if (dicCondition.ContainsKey("id")) //按id进行查询
            {
                string id = dicCondition["id"];
                if (id != "")
                {
                    sb.Append(" and id=@id");
                    paraList.Add(new SqlParameter("@id", id));
                }
            }
            if (dicCondition.ContainsKey("owner")) //按车辆所有人进行查询
            {
                string owner = dicCondition["owner"];
                if (owner != "")
                {
                    sb.Append(" and charindex(@owner,owner)>0 ");
                    paraList.Add(new SqlParameter("@owner", owner));
                }
            }
            if (dicCondition.ContainsKey("telephone")) //按联系电话进行查询
            {
                string telephone = dicCondition["telephone"];
                if (telephone != "")
                {
                    sb.Append(" and telephone=@telephone");
                    paraList.Add(new SqlParameter("@telephone", telephone));
                }
            }
            if (dicCondition.ContainsKey("carNo")) //按车牌号码进行查询
            {
                string carNo = dicCondition["carNo"];
                if (carNo != "")
                {
                    sb.Append(" and charindex(@carNo,carNo)>0 ");
                    paraList.Add(new SqlParameter("@carNo", carNo));
                }
            }
            if (dicCondition.ContainsKey("carType")) //按车型进行查询
            {
                string carType = dicCondition["carType"];
                if (carType != "")
                {
                    sb.Append(" and carType=@carType");
                    paraList.Add(new SqlParameter("@carType", carType));
                }
            }
            if (dicCondition.ContainsKey("loadNo")) //按发动机号进行查询
            {
                string loadNo = dicCondition["loadNo"];
                if (loadNo != "")
                {
                    sb.Append(" and loadNo=@loadNo");
                    paraList.Add(new SqlParameter("@loadNo", loadNo));
                }
            }
            if (dicCondition.ContainsKey("shelfNo")) //按大架号进行查询
            {
                string shelfNo = dicCondition["shelfNo"];
                if (shelfNo != "")
                {
                    sb.Append(" and shelfNo=@shelfNo");
                    paraList.Add(new SqlParameter("@shelfNo", shelfNo));
                }
            }
            if (dicCondition.ContainsKey("addDate")) //按登记日期进行查询
            {
                string addDate = dicCondition["addDate"];
                if (addDate != "")
                {
                    sb.Append(" and addDate=@addDate");
                    paraList.Add(new SqlParameter("@addDate", addDate));
                }
            }
            if (dicCondition.ContainsKey("weights")) //按吨位进行查询
            {
                string weights = dicCondition["weights"];
                if (weights != "")
                {
                    sb.Append(" and weights=@weights");
                    paraList.Add(new SqlParameter("@weights", weights));
                }
            }
            if (dicCondition.ContainsKey("cardNo")) //按二维卡号进行查询
            {
                string cardNo = dicCondition["cardNo"];
                if (cardNo != "")
                {
                    sb.Append(" and cardNo=@cardNo");
                    paraList.Add(new SqlParameter("@cardNo", cardNo));
                }
            }
            if (dicCondition.ContainsKey("date1")) //按到期时间1进行查询
            {
                string date1 = dicCondition["date1"];
                if (date1 != "")
                {
                    sb.Append(" and date1=@date1");
                    paraList.Add(new SqlParameter("@date1", date1));
                }
            }
            if (dicCondition.ContainsKey("date2")) //按到期时间2进行查询
            {
                string date2 = dicCondition["date2"];
                if (date2 != "")
                {
                    sb.Append(" and date2=@date2");
                    paraList.Add(new SqlParameter("@date2", date2));
                }
            }
            if (dicCondition.ContainsKey("date3")) //按到期时间3进行查询
            {
                string date3 = dicCondition["date3"];
                if (date3 != "")
                {
                    sb.Append(" and date3=@date3");
                    paraList.Add(new SqlParameter("@date3", date3));
                }
            }
            if (dicCondition.ContainsKey("endDate")) //按营运到期进行查询
            {
                string endDate = dicCondition["endDate"];
                if (endDate != "")
                {
                    sb.Append(" and endDate=@endDate");
                    paraList.Add(new SqlParameter("@endDate", endDate));
                }
            }
            if (dicCondition.ContainsKey("sortDate")) //按排序时间进行查询
            {
                string sortDate = dicCondition["sortDate"];
                if (sortDate != "")
                {
                    sb.Append(" and sortDate=@sortDate");
                    paraList.Add(new SqlParameter("@sortDate", sortDate));
                }
            }
            DataSet dset = GetDataset(sb.ToString(), paraList, fields);
            return dset;
        }
        /// <summary>
        /// 获取当前页的datatable
        /// </summary>
        /// <param name="dicCondition">条件词典</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageHtml">分页导航html</param>
        /// <param name="pageSize">每页记录数，默认30</param>
        /// <returns></returns>
        public DataTable getOnePage(Dictionary<string, string> dicCondition, int currentPage, out string pageHtml, int pageSize = 0)
        {
            DataSet dset = GetDataset(dicCondition);
            return LIB.pager.getOnePage(dset, currentPage, pageSize, out pageHtml);
        } 

        /// <summary>
        /// 获得一条记录model
        /// </summary>
        public Model.carMaintainInfo GetModel(int id)
        {
            var paraList = new List<SqlParameter>();
            paraList.Add(new SqlParameter("@id", id));
            DataRow dr = GetRow("id=@id", paraList, "");
            return dr == null ? null : DatarowToModel(dr);
        }

        #endregion

        #region 增删改操作 
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(BZZ.Model.carMaintainInfo model = null)
        {
            return doAdd(model);
        }
        /// <summary>
        /// 增加多条数据,返回数据条数
        /// </summary>
        public int AddList(List<BZZ.Model.carMaintainInfo> list)
        {
            foreach (var model in list)
            {
                doAdd(model);
            }
            return list.Count;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(BZZ.Model.carMaintainInfo model = null)
        {
            return doUpdate(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(int id)
        {
            return doDelete(id);
        }
        /// <summary>
        /// 删除多条数据
        /// </summary>
        public int Delete(string ids)
        {
            return doDelete(ids);
        }
        #endregion
        
        #endregion

        #region  私有方法（系统生成）

        #region GetMaxId
        /// <summary>
        /// 得到最大ID (此函数2个参数都可为空)
        /// </summary>
        private int GetMaxId(string strWhere = "", List<SqlParameter> paraList = null)
        {
            string sql = "select max(id) from BZZ_carMaintainInfo";
            if (strWhere.Length > 0) sql += " where " + strWhere;
            return worker.ExecuteCount(sql);
        }

        #endregion

        #region Exists
        /// <summary>
        /// 是否存在该记录 (此函数2个参数都可为空)
        /// </summary>
        private bool Exists(string strWhere = "", List<SqlParameter> paraList = null)
        {
            string sql = "select count(*) from BZZ_carMaintainInfo";
            if (strWhere.Length > 0) sql += " where " + strWhere;
            int num = worker.ExecuteCount(sql, paraList);
            return num == 0 ? false : true;
        }
        #endregion

        #region Add
        /// <summary>
        /// 增加一条数据,返回自增的id
        /// </summary>
        private int doAdd(BZZ.Model.carMaintainInfo model = null)
        {
            if (model == null) model = this;
            var strSql = new StringBuilder();
            strSql.Append("insert into BZZ_carMaintainInfo(");
            strSql.Append("owner,telephone,carNo,carType,loadNo,shelfNo,addDate,weights,cardNo,date1,date2,date3,endDate,sortDate)");
            strSql.Append(" values (");
            strSql.Append(" @owner, @telephone, @carNo, @carType, @loadNo, @shelfNo, @addDate, @weights, @cardNo, @date1, @date2, @date3, @endDate, @sortDate)");
            //strSql.Append(";select @@IDENTITY");
            var list = new List<SqlParameter>();
			list.Add(new SqlParameter("@owner",model.owner ));
			list.Add(new SqlParameter("@telephone",model.telephone ));
			list.Add(new SqlParameter("@carNo",model.carNo ));
			list.Add(new SqlParameter("@carType",model.carType ));
			list.Add(new SqlParameter("@loadNo",model.loadNo ));
			list.Add(new SqlParameter("@shelfNo",model.shelfNo ));
			list.Add(new SqlParameter("@addDate",model.addDate ));
			list.Add(new SqlParameter("@weights",model.weights ));
			list.Add(new SqlParameter("@cardNo",model.cardNo ));
			list.Add(new SqlParameter("@date1",model.date1 ));
			list.Add(new SqlParameter("@date2",model.date2 ));
			list.Add(new SqlParameter("@date3",model.date3 ));
			list.Add(new SqlParameter("@endDate",model.endDate ));
			list.Add(new SqlParameter("@sortDate",model.sortDate ));
            return worker.ExecuteInsert(strSql.ToString(), list);
        }

        #endregion

        #region Update

        /// <summary>
        /// 更新一条数据,返回影响的行数
        /// </summary>
        /// <param name="model">要更新的数据</param>
        /// <param name="updateFld">更新的目标字段，为空则是除了id外的所有字段</param>
        /// <param name="strWhere">更新条件，为空则为model中的id字段</param>
        /// <param name="paraList">更新条件的附加参数，如和内部参数冲突则忽略</param>
        /// <returns></returns>
        private int doUpdate(BZZ.Model.carMaintainInfo model , string updateFld = "", string strWhere = "", List<SqlParameter> paraList = null)
        {
            if (model == null) model = this;
            var strSql = new StringBuilder();
            var list = new List<SqlParameter>();
            strSql.Append("update BZZ_carMaintainInfo set ");
            #region 更新的目标字段
            if (updateFld == "")
            {
                strSql.Append("owner=@owner,");
                list.Add(new SqlParameter("@owner", model.owner));//车辆所有人
                strSql.Append("telephone=@telephone,");
                list.Add(new SqlParameter("@telephone", model.telephone));//联系电话
                strSql.Append("carNo=@carNo,");
                list.Add(new SqlParameter("@carNo", model.carNo));//车牌号码
                strSql.Append("carType=@carType,");
                list.Add(new SqlParameter("@carType", model.carType));//车型
                strSql.Append("loadNo=@loadNo,");
                list.Add(new SqlParameter("@loadNo", model.loadNo));//发动机号
                strSql.Append("shelfNo=@shelfNo,");
                list.Add(new SqlParameter("@shelfNo", model.shelfNo));//大架号
                strSql.Append("addDate=@addDate,");
                list.Add(new SqlParameter("@addDate", model.addDate));//登记日期
                strSql.Append("weights=@weights,");
                list.Add(new SqlParameter("@weights", model.weights));//吨位
                strSql.Append("cardNo=@cardNo,");
                list.Add(new SqlParameter("@cardNo", model.cardNo));//二维卡号
                strSql.Append("date1=@date1,");
                list.Add(new SqlParameter("@date1", model.date1));//到期时间1
                strSql.Append("date2=@date2,");
                list.Add(new SqlParameter("@date2", model.date2));//到期时间2
                strSql.Append("date3=@date3,");
                list.Add(new SqlParameter("@date3", model.date3));//到期时间3
                strSql.Append("endDate=@endDate,");
                list.Add(new SqlParameter("@endDate", model.endDate));//营运到期
                strSql.Append("sortDate=@sortDate");
                list.Add(new SqlParameter("@sortDate", model.sortDate));//排序时间
            }
            else
            {
                ///只更新updatefld列表中的字段
                updateFld = "," + updateFld + ",";
                bool hasFld = false;
                if (updateFld.IndexOf("owner") > 0)
                {
                    hasFld = true;
                    strSql.Append("owner=@owner,");
                    list.Add(new SqlParameter("@owner", model.owner));//车辆所有人
                }
                if (updateFld.IndexOf("telephone") > 0)
                {
                    hasFld = true;
                    strSql.Append("telephone=@telephone,");
                    list.Add(new SqlParameter("@telephone", model.telephone));//联系电话
                }
                if (updateFld.IndexOf("carNo") > 0)
                {
                    hasFld = true;
                    strSql.Append("carNo=@carNo,");
                    list.Add(new SqlParameter("@carNo", model.carNo));//车牌号码
                }
                if (updateFld.IndexOf("carType") > 0)
                {
                    hasFld = true;
                    strSql.Append("carType=@carType,");
                    list.Add(new SqlParameter("@carType", model.carType));//车型
                }
                if (updateFld.IndexOf("loadNo") > 0)
                {
                    hasFld = true;
                    strSql.Append("loadNo=@loadNo,");
                    list.Add(new SqlParameter("@loadNo", model.loadNo));//发动机号
                }
                if (updateFld.IndexOf("shelfNo") > 0)
                {
                    hasFld = true;
                    strSql.Append("shelfNo=@shelfNo,");
                    list.Add(new SqlParameter("@shelfNo", model.shelfNo));//大架号
                }
                if (updateFld.IndexOf("addDate") > 0)
                {
                    hasFld = true;
                    strSql.Append("addDate=@addDate,");
                    list.Add(new SqlParameter("@addDate", model.addDate));//登记日期
                }
                if (updateFld.IndexOf("weights") > 0)
                {
                    hasFld = true;
                    strSql.Append("weights=@weights,");
                    list.Add(new SqlParameter("@weights", model.weights));//吨位
                }
                if (updateFld.IndexOf("cardNo") > 0)
                {
                    hasFld = true;
                    strSql.Append("cardNo=@cardNo,");
                    list.Add(new SqlParameter("@cardNo", model.cardNo));//二维卡号
                }
                if (updateFld.IndexOf("date1") > 0)
                {
                    hasFld = true;
                    strSql.Append("date1=@date1,");
                    list.Add(new SqlParameter("@date1", model.date1));//到期时间1
                }
                if (updateFld.IndexOf("date2") > 0)
                {
                    hasFld = true;
                    strSql.Append("date2=@date2,");
                    list.Add(new SqlParameter("@date2", model.date2));//到期时间2
                }
                if (updateFld.IndexOf("date3") > 0)
                {
                    hasFld = true;
                    strSql.Append("date3=@date3,");
                    list.Add(new SqlParameter("@date3", model.date3));//到期时间3
                }
                if (updateFld.IndexOf("endDate") > 0)
                {
                    hasFld = true;
                    strSql.Append("endDate=@endDate,");
                    list.Add(new SqlParameter("@endDate", model.endDate));//营运到期
                }
                if (updateFld.IndexOf("sortDate") > 0)
                {
                    hasFld = true;
                    strSql.Append("sortDate=@sortDate");
                    list.Add(new SqlParameter("@sortDate", model.sortDate));//排序时间
                }
                if (hasFld) strSql.Remove(strSql.Length - 1, 1);
                else return 0;
            } 
            #endregion
            #region 更新的条件
            if (strWhere.Length < 3)
            {
                strSql.Append(" where id=@id ");
                list.Add(new SqlParameter("@id", model.id));//owner
            }
            else
            {
                ///更新条件，此处需谨慎以免意外
                strSql.Append(" where ");
                strSql.Append(strWhere);
            } 
            #endregion
            #region 更新条件中的附件参数
            ///where语句的参数，如果updatefld里没有此参数，则可以在此处附加（重复的忽略）
            ///此处参数化仅仅是为了过滤输入参数，可以不是model的字段。或者不需要更新但需要作为条件判断的字段值
            if (paraList != null)
            {
                foreach (var para in paraList)
                {
                    if (!list.Contains(para))
                    {
                        list.Add(para);
                    }
                }
            } 
            #endregion
            return worker.ExecuteNonQuery(strSql.ToString(), list);
        }

        /// <summary>
        /// 执行sql语句并返回影响记录条数（请在扩展方法中写新函数，不建议直接调用）
        /// </summary>
        private int doUpdate(string strUpdateSql, List<SqlParameter> paraList = null)
        {
            strUpdateSql = strUpdateSql.Replace("[tbl]", "BZZ_carMaintainInfo");
            return worker.ExecuteNonQuery(strUpdateSql, paraList);
        }

        #endregion

        #region Delete
        /// <summary>
        /// 删除一条数据
        /// </summary>
        private int doDelete(int id)
        {
            var strSql = new StringBuilder();
            strSql.Append("delete from BZZ_carMaintainInfo ");
            strSql.Append(" where id=@id ");
            List<SqlParameter> list = new List<SqlParameter>();
            list.Add(new SqlParameter("@id", id));

            return worker.ExecuteNonQuery(strSql.ToString(), list);
        }
        /// <summary>
        /// 删除多条数据
        /// </summary>
        private int doDelete(string ids)
        {
            #region 检查ids的格式，必须是逗号分隔的数字 
            string[] arrIDs = ids.Split(',');
            if (arrIDs.Length <= 0) return 0;
            else
            {
                int tmpID = 0;
                foreach (string sTmpID in arrIDs)
                {
                    int.TryParse(sTmpID, out tmpID);
                    if (tmpID == 0) return 0;
                }
            } 
            #endregion
            var strSql = new StringBuilder();
            strSql.Append("delete from BZZ_carMaintainInfo ");
            strSql.Append(" where id in (");
            strSql.Append(ids);
            strSql.Append(")");

            return worker.ExecuteNonQuery(strSql.ToString());
        }

        /// <summary>
        /// 根据where语句删除数据
        /// </summary>
        private int doDelete(string strWhere, List<SqlParameter> paraList = null)
        {
            var strSql = new StringBuilder();
            strSql.Append("delete from BZZ_carMaintainInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where ");
                strSql.Append(strWhere);
            }
            return worker.ExecuteNonQuery(strSql.ToString(), paraList);
        }
        #endregion

        #region  获得一个字段值
        /// <summary>
        /// 获得数据列表(参数化)
        /// </summary>
        private string GetField(string fieldName, string strWhere = "", List<SqlParameter> paraList = null)
        {
            var strSql = new StringBuilder();
            strSql.Append("select top 1 ");
            strSql.Append(fieldName);
            strSql.Append(" FROM BZZ_carMaintainInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return worker.ExecuteScalar(strSql.ToString(), paraList);
        }


        /// <summary>
        /// 获得记录条数count(*)
        /// </summary>
        private int GetCount(string strWhere = "", List<SqlParameter> paraList = null)
        {
            var strSql = new StringBuilder();
            strSql.Append("select count(*) ");
            strSql.Append(" FROM BZZ_carMaintainInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return worker.ExecuteCount(strSql.ToString(), paraList);
        }
        #endregion

        #region  获得一条记录

        /// <summary>
        /// 用sql语句返回一个datarow（请在扩展方法中写新函数，不建议直接调用）
        /// </summary>
        private DataRow GetRowBySql(string strSelectSql, List<SqlParameter> cmdParams = null)
        {
            return worker.ExecuteOneRow(strSelectSql, cmdParams);
        }

        /// <summary>
        /// 获得一条记录
        /// </summary>
        private DataRow GetRow(string strWhere, List<SqlParameter> paraList = null, string dataFields = "")
        {
            var strSql = new StringBuilder();
            if (dataFields == null|| dataFields=="")  dataFields = "id,owner,telephone,carNo,carType,loadNo,shelfNo,addDate,weights,cardNo,date1,date2,date3,endDate,sortDate";
            strSql.Append("select top 1 ");
            strSql.Append(dataFields);
            strSql.Append(" FROM BZZ_carMaintainInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return worker.ExecuteOneRow(strSql.ToString(), paraList);
        }

        /// <summary>
        /// 获得一条记录model
        /// </summary>
        private Model.carMaintainInfo GetModel(string strWhere = "", List<SqlParameter> paraList = null)
        {
            DataRow dr = GetRow(strWhere, paraList, "");
            return dr == null ? null : DatarowToModel(dr);
        }
        #endregion

        #region  获得dataset列表
        /// <summary>
        /// 用sql语句返回一个dataset
        /// </summary>
        /// <param name="strSelectSql">查询sql语句</param>
        /// <param name="paraList">输入参数列表</param>
        private DataSet GetDatasetBySql(string strSelectSql, List<SqlParameter> paraList = null)
        {
            return worker.Execute(strSelectSql, paraList);
        }


        /// <summary>
        /// 根据页码获取当前一页的数据
        /// </summary>
        /// <param name="currentPage">页码</param>
        /// <param name="pageSize">每页的记录条数</param>
        /// <param name="strWhere">查询子句，不包括order by</param>
        /// <param name="strOrderBy">查询order by子句</param>
        /// <param name="paraList">参数列表</param>
        /// <param name="dataFields">要查询的字段列表，为空表示所有字段</param>
        /// <param name="tblName">表名，支持多表</param>
        private DataSet GetDatasetByPageSql(int currentPage, int pageSize = 30, string strWhere = "", string strOrderBy = "order by id desc", List<SqlParameter> paraList = null, string dataFields = "", string tblName = "BZZ_carMaintainInfo")
        {
            return worker.ExecutePageSql(currentPage, pageSize, strWhere, strOrderBy, paraList, dataFields, tblName);
        }
        /// <summary>
        /// 获得dataset列表
        /// </summary>
        /// <param name="strWhere">查询条件，可带order by语句</param>
        /// <param name="paraList">输入参数列表</param>
        /// <param name="dataFields">获取的字段列表，传递空则表示所有</param>
        /// <param name="topN">获取的条数</param>
        private DataSet GetDataset(string strWhere = "", List<SqlParameter> paraList = null, string dataFields = "", int topN = 0)
        {
            var strSql = new StringBuilder();
            if (dataFields == "") dataFields = "id,owner,telephone,carNo,carType,loadNo,shelfNo,addDate,weights,cardNo,date1,date2,date3,endDate,sortDate,datediff(d,getdate(),sortdate) as days";
            strSql.Append("select ");
            if (topN > 0) strSql.Append("top " + topN.ToString() + " ");
            strSql.Append(dataFields);
            strSql.Append(" FROM BZZ_carMaintainInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by sortDate asc");

            return worker.Execute(strSql.ToString(), paraList);
        }

        /// <summary>
        /// 获得modellist
        /// </summary>
        /// <param name="strWhere">查询条件，可带order by语句</param>
        /// <param name="paraList">输入参数列表</param>
        /// <param name="dataFields">获取的字段列表，传递空则表示所有</param>
        /// <param name="topN">获取的条数</param>
        private List<Model.carMaintainInfo> GetModelList(string strWhere = "", List<SqlParameter> paraList = null, string dataFields = "", int topN = 0)
        {
            DataSet dset = GetDataset(strWhere, paraList, dataFields, topN);
            if (dset == null) return null;
            else return DatatableToModelList(dset.Tables[0]);
        }
        #endregion

        #region  change to model
        /// <summary>
        /// 把数据从datatable转存成modellist
        /// </summary>
        private List<Model.carMaintainInfo> DatatableToModelList(DataTable dt)
        {
            List<Model.carMaintainInfo> modelList = new List<Model.carMaintainInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                for (int n = 0; n < rowsCount; n++)
                {
                    Model.carMaintainInfo model = new Model.carMaintainInfo();
                    model = DatarowToModel(dt.Rows[n]);
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        /// <summary>
        /// 把数据从datarow转存成model
        /// </summary>
        private BZZ.Model.carMaintainInfo DatarowToModel(DataRow dr)
        {
            Model.carMaintainInfo model = new Model.carMaintainInfo();
            model.id = dr["id"] == DBNull.Value ? 0 : int.Parse(dr["id"].ToString());//id
            model.owner = dr["owner"].ToString();//车辆所有人
            model.telephone = dr["telephone"].ToString();//联系电话
            model.carNo = dr["carNo"].ToString();//车牌号码
            model.carType = dr["carType"].ToString();//车型
            model.loadNo = dr["loadNo"].ToString();//发动机号
            model.shelfNo = dr["shelfNo"].ToString();//大架号
            if(dr["addDate"] != DBNull.Value)model.addDate=DateTime.Parse(dr["addDate"].ToString());//登记日期
            model.weights = dr["weights"].ToString();//吨位
            model.cardNo = dr["cardNo"].ToString();//二维卡号
            if(dr["date1"] != DBNull.Value)model.date1= DateTime.Parse(dr["date1"].ToString());//到期时间1
            if(dr["date2"] != DBNull.Value)model.date2= DateTime.Parse(dr["date2"].ToString());//到期时间2
            if( dr["date3"] != DBNull.Value)model.date3= DateTime.Parse(dr["date3"].ToString());//到期时间3
            if( dr["endDate"] != DBNull.Value)model.endDate= DateTime.Parse(dr["endDate"].ToString());//营运到期
            if( dr["sortDate"] != DBNull.Value)model.sortDate= DateTime.Parse(dr["sortDate"].ToString());//排序时间
            return model;
        }


        #endregion

        #endregion

		#region 数据模型
		public int id { set; get; } //id
		public string owner { set; get; } //车辆所有人
		public string telephone { set; get; } //联系电话
		public string carNo { set; get; } //车牌号码
		public string carType { set; get; } //车型
		public string loadNo { set; get; } //发动机号
		public string shelfNo { set; get; } //大架号
		public DateTime? addDate { set; get; } //登记日期
		public string weights { set; get; } //吨位
		public string cardNo { set; get; } //二维卡号
		public DateTime? date1 { set; get; } //到期时间1
		public DateTime? date2 { set; get; } //到期时间2
		public DateTime? date3 { set; get; } //到期时间3
		public DateTime? endDate { set; get; } //营运到期
		public DateTime? sortDate { set; get; } //排序时间


            

		#endregion Model

		#region txt document
		/*
        汽车维修信息,carMaintainInfo
id,车辆所有人,联系电话,车牌号码,车型,发动机号,大架号,登记日期,吨位,二维卡号,到期时间1,到期时间2,到期时间3,营运到期,排序时间
id,owner,telephone,carNo,carType,loadNo,shelfNo,addDate,weights,cardNo,date1,date2,date3,endDate,sortDate
i,c100,c20,c50,c20,c30,c30,d,c10,c30,d,d,d,d,d


        --------------------------
-- 创建表[汽车维修信息]开始: 
-- alter table  [BZZ_carMaintainInfo] add
-- IF EXISTS (SELECT 1 FROM sysobjects WHERE xtype='u' AND name='BZZ_carMaintainInfo') drop table BZZ_carMaintainInfo
  CREATE TABLE [BZZ_carMaintainInfo] (
	 [id] integer IDENTITY (1, 1) PRIMARY KEY NOT NULL ,
	 [owner] [varchar] (100),
	 [telephone] [varchar] (20),
	 [carNo] [varchar] (50),
	 [carType] [varchar] (20),
	 [loadNo] [varchar] (30),
	 [shelfNo] [varchar] (30),
	 [addDate] [datetime],
	 [weights] [varchar] (10),
	 [cardNo] [varchar] (30),
	 [date1] [datetime],
	 [date2] [datetime],
	 [date3] [datetime],
	 [endDate] [datetime],
	 [sortDate] [datetime]
  )

         exec sp_addextendedproperty N'MS_Description',N'汽车维修信息 ',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo', NULL, NULL
 exec sp_addextendedproperty N'MS_Description',N'id',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'id'
 exec sp_addextendedproperty N'MS_Description',N'车辆所有人',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'owner'
 exec sp_addextendedproperty N'MS_Description',N'联系电话',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'telephone'
 exec sp_addextendedproperty N'MS_Description',N'车牌号码',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'carNo'
 exec sp_addextendedproperty N'MS_Description',N'车型',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'carType'
 exec sp_addextendedproperty N'MS_Description',N'发动机号',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'loadNo'
 exec sp_addextendedproperty N'MS_Description',N'大架号',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'shelfNo'
 exec sp_addextendedproperty N'MS_Description',N'登记日期',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'addDate'
 exec sp_addextendedproperty N'MS_Description',N'吨位',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'weights'
 exec sp_addextendedproperty N'MS_Description',N'二维卡号',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'cardNo'
 exec sp_addextendedproperty N'MS_Description',N'到期时间1',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'date1'
 exec sp_addextendedproperty N'MS_Description',N'到期时间2',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'date2'
 exec sp_addextendedproperty N'MS_Description',N'到期时间3',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'date3'
 exec sp_addextendedproperty N'MS_Description',N'营运到期',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'endDate'
 exec sp_addextendedproperty N'MS_Description',N'排序时间',N'user',N'dbo',N'table',N'BZZ_carMaintainInfo',N'column',N'sortDate'

        -- 创建表[汽车维修信息]结束。 
--------------------------

		*/
		#endregion document
	}
}


